package com.kpijavatraining6.module2.sessionTools;

import com.kpijavatraining6.module2.sessionTools.AuthorisationMenu;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class UsersDataBase {
    private ArrayList<String> userList;
    public final String PATH = "users.txt";
    public void ShowAllUsersStatistic() {
        try {
            File file = new File(PATH);
            //if file doesn't exist, then create it
            if(!file.exists()) {
                file.createNewFile();
            }
            //Check for name!!!!!
            createUserNamesList();
            for (String userName : userList) {
            UserSession userSession =  new UserSession(userName);
                userSession.showStatistic();
            }
        }
        catch(IOException e){
            System.out.println("unable to show statistic");
        }
    }
    private void createUserNamesList() {
        String line;
        userList = new ArrayList<String>();
        try {
        	Scanner fileIn = new Scanner(new File(PATH));
            while(fileIn.hasNextLine()) {
                line = fileIn.nextLine();
        		String [] array = line.split(" ");
        		userList.add(array[0]);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
}
